package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.*;
import org.apache.commons.lang.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysUserResumeMapper;
import com.ruoyi.system.domain.SysUserResume;
import com.ruoyi.system.service.ISysUserResumeService;
import com.ruoyi.common.core.text.Convert;

/**
 * 简历拆分测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-29
 */
@Service
public class SysUserResumeServiceImpl implements ISysUserResumeService 
{

    Logger logger = LoggerFactory.getLogger(SysUserResumeServiceImpl.class);


    @Autowired
    private SysUserResumeMapper sysUserResumeMapper;

    /**
     * 查询简历拆分测试
     * 
     * @param id 简历拆分测试主键
     * @return 简历拆分测试
     */
    @Override
    public SysUserResume selectSysUserResumeById(String id)
    {
        return sysUserResumeMapper.selectSysUserResumeById(id);
    }

    /**
     * 查询简历拆分测试列表
     * 
     * @param sysUserResume 简历拆分测试
     * @return 简历拆分测试
     */
    @Override
    public List<SysUserResume> selectSysUserResumeList(SysUserResume sysUserResume)
    {
        return sysUserResumeMapper.selectSysUserResumeList(sysUserResume);
    }

    /**
     * 新增简历拆分测试
     * 
     * @param sysUserResume 简历拆分测试
     * @return 结果
     */
    @Override
    public int insertSysUserResume(SysUserResume sysUserResume)
    {
        sysUserResume.setCreateTime(DateUtils.getNowDate());
        return sysUserResumeMapper.insertSysUserResume(sysUserResume);
    }

    /**
     * 修改简历拆分测试
     * 
     * @param sysUserResume 简历拆分测试
     * @return 结果
     */
    @Override
    public int updateSysUserResume(SysUserResume sysUserResume)
    {
        sysUserResume.setUpdateTime(DateUtils.getNowDate());
        return sysUserResumeMapper.updateSysUserResume(sysUserResume);
    }

    /**
     * 批量删除简历拆分测试
     * 
     * @param ids 需要删除的简历拆分测试主键
     * @return 结果
     */
    @Override
    public int deleteSysUserResumeByIds(String ids)
    {
        return sysUserResumeMapper.deleteSysUserResumeByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除简历拆分测试信息
     * 
     * @param id 简历拆分测试主键
     * @return 结果
     */
    @Override
    public int deleteSysUserResumeById(String id)
    {
        return sysUserResumeMapper.deleteSysUserResumeById(id);
    }


    @Override
    public Result resolvingA1701(String A1701, String sid, String pch) {

        if (StringUtils.isNotBlank(A1701))
        {


            A1701 = StringEscapeUtils.unescapeXml(A1701);//格式化特殊字符
        }

        A1701 = ResumeUtil.dealJianliText(A1701);
        List<Map<String, Object>> listmap = FormUtils.getA1701List(A1701);
        List<String> list = null;
        //写入数据库中的数据
        list = SqlUtils.getInsertRsA17Sql_hb(listmap, sid, pch, false);
        list.get(list.size() - 1);
        list.remove(list.size() - 1);
        for(String sql:list){
            Integer integer = sysUserResumeMapper.btchInsert(sql);
            logger.debug("是否插入成功:"+integer);
        }
        return Result.fail("拆分简历失败！");
    }


    @Override
    public AjaxResult getJianlidata(String sid) throws Exception {
        AjaxResult ajaxResult =new AjaxResult();
        List<Map<String, Object>> listmap = sysUserResumeMapper.queryForList(sid);
        if (null == listmap || listmap.isEmpty()) {
            ajaxResult.put(AjaxResult.CODE_TAG,500);
            ajaxResult.put(AjaxResult.DATA_TAG,null);
            ajaxResult.put(AjaxResult.MSG_TAG,"没有简历子集不能生成简历描述！");
            return ajaxResult;
        }
        String str = FormUtils.getJianliFromListMap(listmap);
        ajaxResult.put(AjaxResult.CODE_TAG,0);
        ajaxResult.put(AjaxResult.DATA_TAG,str);
        ajaxResult.put(AjaxResult.MSG_TAG,"成功");
        return ajaxResult;
    }
}
